// 请求域名 格式： https://domain.com
const baseUri = ``;
// const baseUri = 'http://0.0.0.0:8387/api/'

class api {
	constructor(token) {
		this.baseUri = baseUri; // 测试环境API地址
		this.token = token
	}
	get(path, data) {
		return this.reqPromise(path, data, 'GET')
	}
	post(path, data) {
		return this.reqPromise(path, data, 'POST')
	}
	reqPromise(path, data, method) {
		let url = `${this.baseUri}${path}`
		let header = {}
		if (this.token) {
			header['Authori-zation'] = `Bearer ${this.token}`
		}
		return new Promise((resolved, rejected) => {
			uni.request({
				url: url,
				data: data,
				method: method,
				header: header,
				success: (res) => {
					resolved(res)
				},
				fail: (err) => {
					console.log(err)
					rejected(err)
				}
			});
		})
	}

}
let token = uni.getStorageSync('token');
export default new api(token)
export {
	baseUri
}
